﻿
using System.Diagnostics;
using Expressions.Compiler;
using Expressions.Compiler.Internal;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tests
{


    /// <summary>
    ///This is a test class for Test4_ and is intended
    ///to contain all Test4_ Unit Tests
    ///</summary>
    [TestClass()]
    public class Test4
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        private Entity<char> CreateGrammar()
        {
            Terminal<char>[] _ = { '0', '1', '(', ')', '+', '-', '*', '/' };

            Nonterminal<char> G = "G";
            Nonterminal<char> E = "E";
            Nonterminal<char> Eopt = "E'";

            Nonterminal<char> T = "T";
            Nonterminal<char> Topt = "T'";

            Nonterminal<char> F = "F";
            Nonterminal<char> N = "N";

            G.Definition = new Rules<char>
            {
                () => E[false] + Terminal<char>.Default
            };

            E.Definition = new Rules<char>
            {
                () => T[false] + Eopt[true]
            };

            T.Definition = new Rules<char>
            {
                () => F[false] + Topt[true]
            };

            F.Definition = new Rules<char>
            {
                () => N[false],
                () => '(' + E[false] + ')'
            };

            N.Definition = new Rules<char>
            {
                () => '0',
                () => '1'
            };

            Eopt.Definition = new Rules<char>
            {
                () => '+' + E[false],
                () => '-' + E[false]
            };

            Topt.Definition = new Rules<char>
            {
                () => '*' + T[false],
                () => '/' + T[false]
            };


            G.Initialize();
            G.Validate();

            return G;
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_1()
        {
            Entity<char> target = CreateGrammar();
            Parser<char> input = "0".ToCharArray();
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == true;
            Assert.AreEqual(expected, actual);
        }


        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_2()
        {
            Entity<char> target = CreateGrammar();
            Parser<char> input = "(0-((0*1)/1+1))-(1/1".ToCharArray();
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == false;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_3()
        {
            Entity<char> target = CreateGrammar();
            Parser<char> input = "(0-((0*1)/1+1))-(1/1))".ToCharArray();
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == false;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_4()
        {
            Entity<char> target = CreateGrammar();
            Parser<char> input = "(0-((0*1)/1+1))-(1/1)".ToCharArray();
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == true;
            Assert.AreEqual(expected, actual);
        }


        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_5()
        {
            Entity<char> target = CreateGrammar();
            Parser<char> input = "".ToCharArray();
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == false;
            Assert.AreEqual(expected, actual);
        }


        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_6()
        {
            Entity<char> target = CreateGrammar();
            Parser<char> input = "(0+e)".ToCharArray();
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == false;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_7()
        {
            Entity<char> target = CreateGrammar();
            Parser<char> input = "0".ToCharArray();
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == true;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_8()
        {
            Entity<char> target = CreateGrammar();
            Parser<char> input = "(0-1)-1".ToCharArray();
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == true;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_9()
        {
            Entity<char> target = CreateGrammar();
            Parser<char> input = "0(+e)".ToCharArray();
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == false;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_10()
        {
            Entity<char> target = CreateGrammar();
            Parser<char> input = "(0-1)+1".ToCharArray();
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == true;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_11()
        {
            Entity<char> target = CreateGrammar();
            Parser<char> input = "(0-((0*1)/1+1))-(1/1)".ToCharArray();
            target.Parse(input);
            string expected = "(0-((0*1)/1+1))-(1/1)";
            string actual = input.Text;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_12()
        {
            Nonterminal<char> target = "P";
            bool expected = false;
            bool actual = target.Equals((Entity<char>)null);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_13()
        {
            Nonterminal<char> target = "P";
            Nonterminal<char> Q = "P";
            bool expected = true;
            bool actual = target.GetHashCode() == Q.GetHashCode();
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_14()
        {
            Tokens<char> stream = new Tokens<char> { '(' };
            bool expected = true;
            bool actual = stream.GetEnumerator() != null;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_15()
        {
            Nonterminal<char> target = "P";
            bool expected = false;
            bool actual = target.Equals((char)Terminal<char>.Default);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_16()
        {
            Nonterminal<char> target = "P";
            bool expected = false;
            bool actual = target.Equals((string)Terminal<char>.Default.ToString());
            Assert.AreEqual(expected, actual);
        }

#if TRACE
        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_17()
        {
            Nonterminal<char> target = "P";
            Reference<char> reference = new Reference<char>(target, true);
            bool expected = true;
            bool actual = reference.Name == target.Name;
            Assert.AreEqual(expected, actual);
        }
#endif

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_18()
        {
            Nonterminal<char> target = "Q";
            bool expected = true;
            bool actual = target.Equals(target);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_19()
        {
            Nonterminal<char> target1 = "Q";
            Nonterminal<char> target2 = "Q";
            bool expected = true;
            bool actual = target1.Equals((Entity<char>)target2);
            Assert.AreEqual(expected, actual);
        }
    }
}
